import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { AddAndEditForm, AddServiceQuery, AddServiceVO, ProductManagementQuery, ProductManagementVO, SettlementConfigurationForm, addOrEditServiceForm } from './types';

/**
 * 查询服务商列表
 * @param query
 */
export const serviceList = (query: AddServiceQuery): AxiosPromise<AddServiceVO[]> => {
  return request({
    url: '/payment/syd/list',
    method: 'get',
    params: query
  });
};


/**
 * 添加&修改服务商
 */
export const addOrEditService = (data: addOrEditServiceForm, method: string) => {
  return request({
    url: '/payment/syd',
    method,
    data,
  });
};

/**
 * 服务商详情
*/
export const serviceDetail = (id: string | number) => {
  return request({
    url: `/payment/syd/${id}`,
    method: 'get',
  });
};

/**
 *  查询服务商产品列表(分页)
 * @param query
 */
export const productManagementList = (query: ProductManagementQuery): AxiosPromise<ProductManagementVO[]> => {
  return request({
    url: '/payment/sydProduct/list',
    method: 'get',
    params: query
  });
};

/**
 *  新增&修改服务商产品
 * @param query
 */
export const addOrEditProductManagement = (data: AddAndEditForm, method: string) => {
  return request({
    url: `/payment/sydProduct`,
    method,
    data
  });
};


/**
 *  新增&修改服务商产品
 * @param query
 */
export const productUpDown = (data: any) => {
  return request({
    url: `/payment/sydProduct/upDown`,
    method:'put',
    headers: {
    	  'Content-Type': 'application/x-www-form-urlencoded'
    	},
    data
  });
};


/**
 *  查询服务商产品列表(分页)
 * @param query
 */
export const productManagementDetail = (id: string | number) => {
  return request({
    url: `/payment/sydProduct/${id}`,
    method: 'get',
  });
};

/**
 *  查询发票类目列表
 * @param query
 */
export const getInvoiceList = () => {
  return request({
    url: `/payment/invoiceType/getListInvoice`,
    method: 'get',

  });
};
//税地归属地
export const getSysThirdPlatformList = () => {
  return request({
    url: `/payment/sysThirdPlatform/list`,
    method: 'get',
  });
};
// 结算配置

/**
 *  获取配置大类下面的组信息
 * @param query
 */
export const getConfGroupByUnit = (unit_id: string | number, class_alias: string = 'settlement.type') => {
  return request({
    url: `/payment/sydConfig/getConfGroupByUnit/${unit_id}/${class_alias}`,
    method: 'get',
  });
};

/**
 *  根据配置组查询配置项明细
 * @param query
 */
export const getConfDetailByUnit = (unit_id: string | number, conf_group: string | number | boolean) => {
  return request({
    url: `/payment/sydConfig/getConfDetailByUnit/${unit_id}/${conf_group}`,
    method: 'get',
  });
};

/**
 *  获取结算中心的支付宝签约信息
 * @param query
 */
export const getSignInfo = (sydId: string | number) => {
  return request({
    url: `/payment/syd/getSignInfo`,
    method: 'post',
    params: {
      sydId,
      passage: '支付宝'
    }
  });
};

/**
 *  编辑配置项明细
 * @param query
 */
export const editConfDetail = (data: SettlementConfigurationForm) => {
  return request({
    url: `/payment/sydConfig/editConfDetail`,
    method: 'post',
    data
  });
};

/**
 *  创建资金账户
 * @param query
 */
export const creatXNnum = (id: string | number,sydName:string) => {
  return request({
    url: `/payment/syd/creatXNnum`,
    method: 'post',
    params: {
      id,
      gsmc:sydName
    }
  });
};


export default {
  serviceList,
  addOrEditService,
  serviceDetail,
  productManagementList,
  addOrEditProductManagement,
  productManagementDetail,
  getInvoiceList,
  getConfGroupByUnit,
  getConfDetailByUnit,
  getSignInfo,
  editConfDetail,
  creatXNnum,
  productUpDown,
  getSysThirdPlatformList
};
